home *** CD-ROM | disk | FTP | other *** search
/ Revista CD Expert 8 / Revista CD Expert nº 08 CD1.iso / Utilitarios / Programacao / Bloodshed Dev-C++ 2.0 / _SETUP.1 / sehtest.c < prev    next >
C/C++ Source or Header  |  1999-02-01  |  2KB  |  73 lines

  1. /*
  2.  * This file tests some of the basics of structured exception handling as
  3.  * implemented in excpt.h and the Windows API header files.
  4.  *
  5.  * The program installs two exception handlers, then attempts to write to
  6.  * a pointer to an invalid address. This causes an exception which passes
  7.  * through the exception handlers and on to the default system exception
  8.  * handler. That handler brings up the dialog box all Windows users know
  9.  * and love, and then the program is terminated.
  10.  *
  11.  * You might note that after the initial run up through our exception frames
  12.  * we get a second run up through them with the exception code
  13.  * STATUS_INVALID_DISPOSITION and the code EH_UNWINDING. This seems normal
  14.  * except that the code got changed from the previous STATUS_ACCESS_VIOLATION.
  15.  * I don't understand that bit particularly.
  16.  */
  17.  
  18. #include <stdio.h>
  19. #include <excpt.h>
  20.  
  21. #include "exutil.h"
  22.  
  23. EXCEPTION_DISPOSITION
  24. my_handler (
  25.     struct _EXCEPTION_RECORD* pExceptionRec,
  26.     void* pEstablisherFrame,
  27.     struct _CONTEXT* pContextRecord,
  28.     void* pDispatcherContext
  29.     )
  30. {
  31.     printf ("In my exception handler!\n");
  32.     DumpExceptionRecord (pExceptionRec);
  33.     return ExceptionContinueSearch;
  34. }
  35.  
  36. EXCEPTION_DISPOSITION
  37. my_handler2 (
  38.     struct _EXCEPTION_RECORD* pExceptionRec,
  39.     void* pEstablisherFrame,
  40.     struct _CONTEXT* pContextRecord,
  41.     void* pDispatcherContext
  42.     )
  43. {
  44.     printf ("In top exception handler!\n");
  45.     DumpExceptionRecord (pExceptionRec);
  46.     return ExceptionContinueSearch;
  47. }
  48.  
  49. main ()
  50. {
  51.     char*    x;
  52.  
  53.     printf ("my_handler2 = %08x\n", my_handler2);
  54.     printf ("my_handler = %08x\n", my_handler);
  55.  
  56.     WalkExceptionHandlers();
  57.  
  58.     __try1(my_handler2)
  59.     x = (char*) 10;
  60.  
  61.     WalkExceptionHandlers();
  62.  
  63.     __try1(my_handler)
  64.  
  65.     WalkExceptionHandlers();
  66.  
  67.     *x = 1;
  68.     __except1
  69.     __except1
  70.     printf ("Finished!\n");
  71. }
  72.  
  73.